﻿using System;
using YmtAuth.Common.Utility;
using YmtAuth.Domain.Model.Safe;
using YmtAuth.Domain.Shard;
using YmtSystem.Infrastructure.EventBusService;

namespace YmtAuth.Domain.DomainEvent
{
    /// <summary>
    /// 用户登录安全验证事件
    /// </summary>
    public class LoginSafeVerifyEvent : IEvent
    {
        public string RequestId { get; set; }

        public LoginSafeVerifyEvent()
        {
            try
            {
                RequestId = HttpHelper.GetHeaderParameter(YmtUserKey.RequestId);
            }
            catch(Exception ex){
                RequestId = Guid.NewGuid().ToString("N");
            }

            ApiId = 0;

            try
            {
                ApiId = YmtAuthSafeConstant.GetApiId(HttpHelper.GetHeaderParameter(YmtAuthSafeConstant.ApiId));
            }
            catch (Exception ex)
            {
                
            }
        }

        public string LoginId { get; set; }
        public int UserId { get; set; }
        public string LoginIp { get; set; }
        public string Summary { get; set; }
        public string AppSource { get; set; }
        public double RunTime { get; set; }
        public string ChannelSource { get; set; }
        public string Terminal { get; set; }
        public string Desc { get; set; }
        public string AuthType { get; set; }
        public int ResponseCode { get; set; }
        public string DeviceId { get; set; }
        public string ClientId { get; set; }

        /// <summary>
        /// 请求接口ID
        /// </summary>
        public int ApiId { get; set; }

        /// <summary>
        /// 安全策略类型; pc, app
        /// </summary>
        public string StrategyType
        {
            get
            {
                return AuthSafeHandleFactory.GetStrategyKey(AppSource);
            }
        }

        /// <summary>
        /// IP区域，国家省份城市
        /// </summary>
        public string IpArea { get; set; }

        /// <summary>
        /// IP区域上次认证时间
        /// </summary>
        public DateTime LastAuthTime { get; set; }

        /// <summary>
        /// 黑名单IP过期时间
        /// </summary>
        public DateTime? ExpiredTime { get; set; }
    }
}
